<%@page import="me.idashu.attg.domain.GoodsEntity"%>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
request.setCharacterEncoding("UTF-8");
String htmlData = request.getParameter("content1") != null ? request.getParameter("content1") : "";
String ad = String.valueOf(request.getAttribute("ad"));
%>
<!doctype html>
<html>
<head>
	<meta charset="utf-8" />
	<title>KindEditor JSP</title>
	<link rel="stylesheet" href="/attg/themes/default/default.css" />
	<link rel="stylesheet" href="/attg/plugins/code/prettify.css" />
	<script charset="utf-8" src="/attg/kindeditor.js"></script>
	<script charset="utf-8" src="/attg/lang/zh_CN.js"></script>
	<script charset="utf-8" src="/attg/plugins/code/prettify.js"></script>
	<link href="/attg/resources/css/bootstrap.min.css" rel="stylesheet"
	media="screen">
	<link href="/attg/resources/css/style.css" rel="stylesheet">
	<script src="/attg/resources/js/jquery-1.9.2.min.js"></script>
	<script src="/attg/resources/js/bootstrap.min.js"></script>
	<script src="/attg/resources/js/js.js"></script>
	<script>
		var editor1;
		KindEditor.ready(function(K) {
			editor1 = K.create('textarea[name="adver_html"]', {
				cssPath : '/attg/plugins/code/prettify.css',
				uploadJson : '/attg/jsp/upload_json.jsp',
				fileManagerJson : '/attg/jsp/file_manager_json.jsp',
				allowFileManager : true,
				afterCreate : function() {
					var self = this;
					K.ctrl(document, 13, function() {
						self.sync();
					});
					K.ctrl(self.edit.doc, 13, function() {
						self.sync();
					});
				}
			});
			prettyPrint();
		});
		function sendValue() {
			var goods_Id = $("#goods_Id").val();
			var adver_Seq = $("#adver_Seq").val();
			var file = $("#file").val();
			var content = editor1.html();
			if ($.trim(file) == null || $.trim(file) == "") {
				alert("图片不能为空");
				return;

			}
			if ($.trim(goods_Id) == null || $.trim(goods_Id) == "") {

				alert("商铺名称不能为空");
				return;

			}
			var adver_starttime = $("#adver_starttime").val();
			if ($.trim(adver_starttime) == null || $.trim(adver_starttime) == "") {
				alert("开始时间不能为空");
				return;
			}
			var adver_endtime = $("#adver_endtime").val();
			if ($.trim(adver_endtime) == null || $.trim(adver_endtime) == "") {
				alert("结束时间不能为空");
				return;
			}
			if ($.trim(adver_Seq) == null || $.trim(adver_Seq) == "") {

				alert("图片顺序不能为空");
				return;
			}
			if ($.trim(content) == null || $.trim(content) == "") {

				alert("编辑内容不能为空");
				return;
			}
			$("#adver_html").val(content);
			$('#form1').submit();
		}
	</script>
</head>
<body>
	<ul class="breadcrumb">
		<li><span id="test">您当前的位置：</span><a href="#">首页</a> <span
			class="divider">>></span></li>
		<li class="active"><%=ad %></li>
	</ul>
	
	<form class="form-horizontal" method="post"
		enctype="multipart/form-data"
		action="/attg/web/manager/ad/add.do" id="form1">
		<div class="control-group">
			<label class="control-label" for="file">图片上传</label>
			<div class="controls">
				<input type="file" id="file" name="file">
				<div class="preview">
					<img src="">
				</div>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="adver_Position">类型</label>
			<div class="controls">
				<select class="select" id="adver_Position" name="adver_Position">
					<option value="s">开机启动页</option>
					<option value="a">首页</option>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="goods_Id">商铺名称</label>
			<div class="controls">
				<select id="goods_Id" name="goods_Id">
					<%
					List<GoodsEntity> listGoods = (List<GoodsEntity>)request.getAttribute("listGoods");
					for(int i=0;i<listGoods.size();i++){
					GoodsEntity goodsEntity = listGoods.get(i);
					int goodsId = goodsEntity.getGoods_id();
					String goodsName = goodsEntity.getGoods_Name();
					%>
				  	<option value="<%=goodsId %>"><%=goodsName %></option>
					<%	
					}
					%>
				</select>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label" for="adver_Desc">广告描述</label>
			<div class="controls">
				<input type="text" id="adver_Desc" name="adver_Desc"
					placeholder="图片描述">
			</div>
		</div>
		<div class="control-group">
		    <label class="control-label" for="adver_starttime">开始时间</label>
		    <div class="controls">
		      <input type="date" class="w120"  id="adver_starttime" name="adver_starttime">
		    </div>
		  </div>
		   <div class="control-group">
		    <label class="control-label" for="adver_endtime">结束时间</label>
		    <div class="controls">
		      <input type="date" class="w120"  id="adver_endtime" name="adver_endtime">
		    </div>
		  </div>
		<div class="control-group">
			<label class="control-label" for="adver_Seq">图片顺序</label>
			<div class="controls">
				<input type="number" id="adver_Seq" name="adver_Seq"
					placeholder="图片顺序">
			</div>
		</div>
		<div class="control-group">
			<div class="controls">
				<textarea name="adver_html" id="adver_html" cols="100" rows="8" style="width:700px;height:200px;visibility:hidden;"></textarea>
			</div>
		</div>
		<div class="control-group">
			<div class="controls" style="margin-left: 43%;">
				<button type="button" class="btn" onclick="sendValue()">确认添加</button>
			</div>
		</div>
	</form>
</body>
</html>
<%!
private String htmlspecialchars(String str) {
	str = str.replaceAll("&", "&amp;");
	str = str.replaceAll("<", "&lt;");
	str = str.replaceAll(">", "&gt;");
	str = str.replaceAll("\"", "&quot;");
	return str;
}
%>